/**
 * 文章基本信息表
 *
 */
module.exports = app => {
	const { STRING, INTEGER, CHAR, Sequelize } = app.Sequelize;
	const Article = app.model.define(
		'article',
		{
			id: {
				type: INTEGER,
				primaryKey: true,
				autoIncrement: true,
				field: 'id'
			},
			//文章标题
			title: {
				type: STRING(100),
				notNull: true,
				field: 'title'
			},
			//文章副标题
			alias: {
				type: STRING(100),
				notNull: false,
				field: 'alias'
			},
			//文章副标题
			summary: {
				type: STRING(1000),
				notNull: false,
				field: 'summary'
			},
			//来源
			source: {
				type: STRING(100),
				field: 'source'
			},
			// 内容
			content: {
				type: Sequelize.STRING(5000),
				field: 'content'
			},
			// 是否置顶
			contentType: {
				type: Sequelize.CHAR(1),
				defaultValue: 1, // 默认不置顶,
				field: 'content_type'
			},
			// 分类id
			categoryId: {
				type: Sequelize.INTEGER(2),
				field: 'category_id'
			},
			//分类标签
			labels: {
				type: STRING(100),
				field: 'labels'
			},
			//外链
			url: {
				type: STRING(100),
				field: 'url'
			},
			// 浏览次数
			viewCount: {
				type: Sequelize.INTEGER(2),
				field: 'view_count',
				defaultValue: 0
			},
			// 文章创建时间
			createTime: {
				type: Sequelize.DATE,
				defaultValue: Sequelize.NOW,
				field: 'create_time'
			},
			// 文档更新时间
			updateTime: {
				type: Sequelize.DATE,
				defaultValue: Sequelize.NOW,
				field: 'update_time'
			},

			// 是否显示
			isShow: {
				type: Sequelize.CHAR(1),
				defaultValue: 0, // 默认不显示,
				field: 'is_show'
			},
			// 是否置顶
			isTop: {
				type: Sequelize.CHAR(1),
				defaultValue: 0, // 默认不置顶,
				field: 'is_top'
			}
		},
		{
			timestamps: false, //去除createAt updateAt
			freezeTableName: true //使用自定义表名
		}
	);

	Article.associate = function() {
		app.model.Article.belongsTo(app.model.Category, { foreignKey: 'categoryId', targetKey: 'id' });
	};
	return Article;
};
